package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.dto.ActivityDto;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/activities")
@Slf4j
@RestController
public class ActivityController {
        @Autowired
        private ActivityService activityService;
        @GetMapping
        public Result list(ActivityDto activityDto){
                PageResult<Activity> pageResult = activityService.selectActivityList(activityDto);
               return Result.success(pageResult);
        }
        //删除活动
        @DeleteMapping("/{id}")
        public Result getById(@PathVariable Integer id){
                activityService.deleteActivityById(id);
                return Result.success();
        }
        //添加活动
        @PostMapping
        public Result add(@RequestBody Activity activity){
                log.info("新增活动{}" , activity);
                activityService.addActivity(activity);
                return Result.success();
        }
        //根据id查询活动
        @GetMapping("/{id}")
        public Result selectActivityById(@PathVariable Integer id){
                Activity activity = activityService.selectActivityById(id);
                return Result.success(activity);
        }
        //修改活动
        @PutMapping
        public Result update(@RequestBody Activity activity){
                log.info("修改活动{}" , activity);
                activityService.updateActivity(activity);
                return Result.success();
        }
        //6. 查询指定类型的活动
        @GetMapping("/type/{type}")
        public Result selectActivityByType(@PathVariable Integer type){
                List<Activity> activityList = activityService.selectActivityByType(type);
                return Result.success(activityList);
        }
}
